package com.axend.vetwavve.fragment

import android.os.Bundle
import android.widget.Toast
import com.android.jws.JwsManager
import com.axend.lib_base.base.fragment.BaseVVDFragment
import com.axend.lib_base.engine.toast.toast

import com.axend.lib_base.ext.addFragment
import com.axend.lib_base.ext.expandTouchArea
import com.axend.lib_base.help.otgserial.SerialManage

import com.axend.lib_base.utils.ScreenAutoAdapter
import com.axend.lib_base.view.dialog.CustomFirmwareUpgradeDialog
import com.axend.lib_service.Constant.designSize
import com.axend.vetwavve.BR
import com.axend.vetwavve.R
import com.axend.vetwavve.activity.MainActivity
import com.axend.vetwavve.databinding.FragmentDesktopBinding
import com.axend.vetwavve.viewmodel.DeskTopViewModel


/**
 * @description主页Fragment
 * @author admins
 * @time 2024/6/7 14:58
 */
class DeskTopFragment : BaseVVDFragment<DeskTopViewModel, FragmentDesktopBinding>() {

    override fun init(savedInstanceState: Bundle?) {

        /*跳转宠物档案记录*/
        mBinding.llOldRecord.expandTouchArea(50)
        mBinding.llOldRecord.setOnClickListener {
            addFragment(
                requireActivity(),
                (requireActivity() as MainActivity).getFragmentContainerId(),
                PetRecordFragment(),
                this@DeskTopFragment,
                null,
                true
            )
        }


        /*新增/编辑宠物档案*/
        mBinding.llNewRecord.expandTouchArea(50)
        mBinding.llNewRecord.setOnClickListener {
            addFragment(
                requireActivity(),
                (requireActivity() as MainActivity).getFragmentContainerId(),
                AddOrEditRecordFragment.newInstance(
                    AddOrEditRecordFragment.PARAMS_ADD,
                    fromFragment = this
                ),
                this@DeskTopFragment,
                null,
                true
            )
        }

        /*固件升级弹窗*/
        mBinding.tvSystemInfo.expandTouchArea(50)
        mBinding.tvSystemInfo.setOnClickListener {
            CustomFirmwareUpgradeDialog(requireActivity() as MainActivity).show(
                requireActivity().supportFragmentManager,
                "CustomFirmwareUpgradeDialog"
            )
        }
    }

    override fun getBindingVariable(): Int = BR.viewmodel

    override fun onResume() {
        super.onResume()
        /*在桌面先打开状态栏*/
        var jwsManager= JwsManager.create(requireContext())
        jwsManager.jwsSetStatusBar(requireContext(), true)
        ScreenAutoAdapter.match(requireActivity(), designSize)

    }


    override fun onDestroy() {
        super.onDestroy()

    }

    override fun onDestroyView() {
        super.onDestroyView()
//        SerialManage.getInstance().colse()
    }


}